//
//  RegisterViewController.m
//  i读
//
//  Created by 123 on 15/10/19.
//  Copyright © 2015年 123. All rights reserved.
//

#import "RegisterViewController.h"
//#import "FillDataViewController.h"
//#import "SVProgressHUD.h"
//#import "LWUtils.h"
//#import "RequestManager.h"
//#import "AppPreference.h"
#import "ViewController.h"
@interface RegisterViewController ()


@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 占字符颜色设置
    [_iphoneField setValue:[[UIColor whiteColor] colorWithAlphaComponent:0.7] forKeyPath:@"_placeholderLabel.textColor"];
    [_identifyField setValue:[[UIColor whiteColor] colorWithAlphaComponent:0.7] forKeyPath:@"_placeholderLabel.textColor"];
    [_codeField setValue:[[UIColor whiteColor] colorWithAlphaComponent:0.7] forKeyPath:@"_placeholderLabel.textColor"];
    [_anyCodeField setValue:[[UIColor whiteColor] colorWithAlphaComponent:0.7] forKeyPath:@"_placeholderLabel.textColor"];
    
    //占字符字体大小设置
    [_iphoneField setValue:[UIFont boldSystemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
    [_identifyField setValue:[UIFont boldSystemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
    [_codeField setValue:[UIFont boldSystemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
    [_anyCodeField setValue:[UIFont boldSystemFontOfSize:12] forKeyPath:@"_placeholderLabel.font"];
    // 按钮圆角
    [_commitBtn.layer setCornerRadius:5.0];
//    [_commitBtn addTarget:self action:@selector(commitBtnCilck:) forControlEvents:UIControlEventTouchUpInside];
    
    _codeField.secureTextEntry = YES;
    _anyCodeField.secureTextEntry = YES;
    NSLog(@"%@",_type) ;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -          ------- 点击事件响应

//返回
- (IBAction)backBtn:(UIButton *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

////提交注册信息
//- (void)commitBtnCilck:(UIButton *)sender{
//    if ([self checkPasswordAvailable]) {
//        if (_type != NULL) {
//            
//            /****接口****/
//            [RequestManager thirdRegistWithThirdId:_QQInfoArr[0] thirdType:_type thirdName:_QQInfoArr[1] headImg:_QQInfoArr[2] phone:_iphoneField.text loginPwd:_codeField.text completionHandler:^(UserModel *userInfo, NSString *reCode, NSString *reMsg){
//                if ([reCode isEqualToString:@"0"]) {
//                    ViewController *view = [[ViewController alloc]init];
//                    
//                    //存储用户数据
//                    [[AppPreference defaultPreference]loginWithUser:userInfo];
//                    [AppPreference defaultPreference].isLogin = YES;
//                    [AppPreference defaultPreference].autoLogin = YES;
//                    [AppPreference defaultPreference].currentUserId = [NSString stringWithFormat:@"%ld",(long)userInfo.userId];
//                    [AppPreference defaultPreference].currentPhone = userInfo.phone;
//                    
//                    
//                    [self.navigationController pushViewController:view animated:YES];
//                    
//                }
//            }];
//        
//        }
//        else{
//        /****接口****/
//        [RequestManager registWithPhone:self.iphoneField.text
//                            loginPwd:self.codeField.text completionHandler:^(UserModel *userInfo, NSString *reCode, NSString *reMsg) {
//                                [[AppPreference defaultPreference]loginWithUser:userInfo];
//                                NSLog(@"===============%@,%@,%@",userInfo,reCode,reMsg);
//                             if ([reCode isEqualToString:@"0"]) {
//                                FillDataViewController *fillDataV = [[FillDataViewController alloc]init];
//                                [self.navigationController pushViewController:fillDataV animated:YES];
//                             }
//                            }];
//    }
//
//    }
//}
//
//#pragma mark -          -------密码规范设置
//- (BOOL)checkPasswordAvailable{
//    
//    if ([self.codeField.text isEqualToString:@""] && [self.anyCodeField.text isEqualToString:@""]) {
//        [SVProgressHUD showErrorWithStatus:@"密码不得为空"];
//        return NO;
//    }
//    
//    if (![self.codeField.text isEqualToString:self.anyCodeField.text]) {
//        [SVProgressHUD showErrorWithStatus:@"两次密码输入不一致!"];
//        return NO;
//    }
//    
//    if (![LWUtils isLetterWithDigital:self.codeField.text]) {
//        [SVProgressHUD showErrorWithStatus:@"密码格式不正确,只能为字母和数字组合!"];
//        return NO;
//    }
//    
//    if (self.codeField.text.length < 6 || self.codeField.text.length > 18) {
//        [SVProgressHUD showErrorWithStatus:@"密码长度为8-20位"];
//        return NO;
//    }
//    
//    
//    return YES;
//}
//
//
//#pragma mark -          ---------  取消键盘响应
//
//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//    
//    UITouch *touch = [touches anyObject];
//    
//    if (![touch.view isKindOfClass: [UITextField class]] || ![touch.view isKindOfClass: [UITextView class]]) {
//        
//        [self.view endEditing:YES];
//        
//    }
//    
//}
//
//#pragma mark -             -------- 验证码点击事件
//
//- (IBAction)identifyBtn:(UIButton *)sender {
//    NSString *type = @"0";
//    if ([self.iphoneField.text isEqualToString:@""]) {
//        [SVProgressHUD showErrorWithStatus:@"请输入手机号"];
//        // 判断是否为合格手机号
//    }else if ([LWUtils isMobileNumberClassification:self.iphoneField.text]) {
//        
//        /****接口****/
//        [RequestManager getRegistCodeWithPhone:self.iphoneField.text type:type
//                          completionHandler:^(NSString *reCode, NSString *reMsg) {
//                              if ([reCode isEqualToString:@"0"]) {
//                                  
//                                  /****** 定时器计时******/
//                                  
//                                 __block int timeout=60; //倒计时时间
//                                  dispatch_queue_t queue  = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//                                  dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
//                                  dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
//                                  dispatch_source_set_event_handler(_timer, ^{
//                                      if(timeout<=0){ //倒计时结束，关闭
//                                          dispatch_source_cancel(_timer);
//                                          dispatch_async(dispatch_get_main_queue(), ^{
//                                              [_codeBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
//                                              _codeBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
//                                              _codeBtn.userInteractionEnabled = YES;
//                                          });
//                                      }else{
//                                          int seconds = timeout % 60;
//                                          NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
//                                          dispatch_async(dispatch_get_main_queue(), ^{
//                                              //设置界面的按钮显示 根据自己需求设置
//                                              [UIView beginAnimations:nil context:nil];
//                                              _codeBtn.titleLabel.text =[NSString stringWithFormat:@"%@秒后重新发送",strTime] ;
//                                            [_codeBtn setTitle:[NSString stringWithFormat:@"%@秒后重新发送",strTime] forState:UIControlStateNormal];
//                                              _codeBtn.titleLabel.font = [UIFont boldSystemFontOfSize:12];
//                                              [UIView commitAnimations];
//                                              _codeBtn.userInteractionEnabled = NO;
//                                          });
//                                          timeout--;
//                                      }
//                                  });
//                                  dispatch_resume(_timer);
//                              }
//                          }];
//    }else{
//        [SVProgressHUD showErrorWithStatus:@"请输入正确手机号"];
//    }
//
//}
@end
